//@author A0081189X
package net.mysoc.w111j.model;

import java.io.Serializable;

/**
 * A simple key-value entry for representing payment types.
 *
 * {@code PaymentType} objects have an id and a name. They are used as labels by {@code Expense} objects.
 */
public class PaymentType implements Serializable {
    /** The ID of this payment type. */
    private int id;
    /** The name of this payment type. */
    private String name;

    /**
     * Nullary constructor. This is used only by the XStream library. Do not use under normal circumstances.
     */
    public PaymentType() {
    }

    /**
     * Constructs a new {@code PaymentType} with the specified id name.
     *
     * @param id   an ID for the payment type.
     * @param name a name for the payment type. The name cannot be null or empty.
     */
    public PaymentType(int id, String name) {
        if (name == null || name.trim().isEmpty()) {
            throw new IllegalArgumentException("Payment Type name should not be null or empty");
        }
        this.id = id;
        this.name = name.trim();
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return name;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        PaymentType paymentType = (PaymentType) o;

        if (id != paymentType.id) return false;
        if (!name.equals(paymentType.name)) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = id;
        result = 31 * result + name.hashCode();
        return result;
    }
}
